//
//  iShare.swift
//  亿享_04
//
//  Created by ibokan on 2017/7/11.
//  Copyright © 2017年 ibokan. All rights reserved.
//

import UIKit

class  iShare: UIViewController {
    fileprivate let cellIdentifier = "WLCellIdentifier"
    
    @IBOutlet weak var bgimg: UIImageView!
    
    var dataArray = [["版本更新"],["功能介绍"],["帮助"],["反馈"]]
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        view.addSubview(headerView)
        view.addSubview(tableView)
    }
    override func didReceiveMemoryWarning() {
        
        super.didReceiveMemoryWarning()
        
    }
    private lazy var headerView: UIView = {
        
        
        let view = UIView(frame: CGRect(x: 0, y: 64, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
        
        //创建logo
        let ilogo = UIImageView(image:UIImage(named:"logo"))
        ilogo.frame = CGRect(x:UIScreen.main.bounds.width/2 - 50, y:40, width:100, height:100)
        let image:CALayer = ilogo.layer
        image.masksToBounds = true
        image.cornerRadius = ilogo.frame.size.height / 4
        view.addSubview(ilogo)
        
        // iShare
        let iShare = UILabel(frame: CGRect(x: 0, y: 140, width: UIScreen.main.bounds.width, height: 50))
        iShare.text =  "iShare"
        iShare.textColor = UIColor.black
        iShare.textAlignment = NSTextAlignment.center
        iShare.font = UIFont(name: "iShare", size: 40)
        view.addSubview(iShare)
        
        // 版本
        let iShareV = UILabel(frame: CGRect(x: 0, y: 175, width: UIScreen.main.bounds.width, height: 30))
        iShareV.text =  "v 1.0.0.1"
        iShareV.textColor = UIColor.gray
        iShareV.textAlignment = NSTextAlignment.center
        iShareV.font = UIFont(name: "iShareV", size: 15)
        view.addSubview(iShareV)
        return view
    }()
    
    private lazy var tableView: UITableView = {
        
        let tab = UITableView(frame: CGRect(x: 0, y: 300, width: UIScreen.main.bounds.width, height: 200), style: .plain)
        tab.backgroundColor = UIColor.clear
//        tab.backgroundColor = UIColor(colorLiteralRed: 255.0 / 255.0, green: 255.0 / 255.0, blue: 255.0 / 255.0, alpha: 1.0)
        tab.separatorStyle = UITableViewCellSeparatorStyle.none
        tab.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        tab.delegate = self
        tab.dataSource = self
        tab.register(UITableViewCell.self, forCellReuseIdentifier: self.cellIdentifier)
        return tab
    }()
    
}
extension iShare: UITableViewDelegate, UITableViewDataSource {
    
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 4
    }
    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
        cell.backgroundColor = UIColor.white
        cell.textLabel?.text = dataArray[indexPath.row][0]
        cell.textLabel?.textColor = UIColor.black
        cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
//        let vc:UIViewController
        switch indexPath.row {
        case 0:
            let alert = UIAlertController(title: "提示", message: "此功能尚未开放", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
            break
        case 1:
            let alert = UIAlertController(title: "提示", message: "此功能尚未开放", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
            break
        case 2:
//            vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "iShare")
//            vc.view.backgroundColor = UIColor.white
//            vc.title = dataArray[indexPath.row][0]
//            show(vc, sender: Any?.self)
            let alert = UIAlertController(title: "提示", message: "此功能尚未开放", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
            break
        case 3:
            let alert = UIAlertController(title: "提示", message: "此功能尚未开放", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
            break
        default:
            break
        }
    }
}

